﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using KinectedMusic.Audio;
using System.Windows.Threading;
using KinectedMusic.Kinect;
using Microsoft.Kinect;

namespace KinectedMusic.Visual
{
    /// <summary>
    /// Interaction logic for TestInstrument.xaml
    /// </summary>
    public partial class TestInstrument : UserControl, IKinectInstrument
    {
        IInstrument instrument;

        public TestInstrument()
        {
            InitializeComponent();
        }


        public bool Initialise(IAudioControl audioControl)
        {
            try
            {
                instrument = audioControl.AddInstrument("4FrontBass");
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }


        public void SendData(Kinect.ColourPerson colourPerson)
        {
            this.Dispatcher.Invoke(DispatcherPriority.Normal, new Action<FrameworkElement, ColourJoint>(MoveGuitar), this.Guitar, colourPerson.Points[JointType.HipCenter]);
        }

        //TODO: fix!!
        private void MoveGuitar(FrameworkElement element, ColourJoint point)
        {
            Canvas.SetLeft(element, point.X - element.ActualWidth / 2.0);
            Canvas.SetTop(element, point.Y - element.ActualHeight / 2.0);
        }
    }
}
